package com.medicine.hbp.ui;

import android.support.v4.app.Fragment;
import android.view.KeyEvent;

import com.medicine.hbp.R;
import com.medicine.hbp.adapter.FragmentAdapter;
import com.medicine.hbp.base.BaseActivity;
import com.medicine.hbp.fragment.CareAboutFragment;
import com.medicine.hbp.kankan.cardslide.CardFragment;
import com.medicine.hbp.page.ViewPageIndex;
import com.medicine.hbp.uitl.NoScrollViewPager;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import org.kymjs.kjframe.ui.BindView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class CardViewActivity extends BaseActivity {
	@BindView(id = R.id.view_page, click = false)
	public static NoScrollViewPager mViewPage;
	@BindView(id = R.id.indicator, click = false)
	public ViewPageIndex indicator;
//	@BindView(id = R.id.img_bq, click = true)
//	public ImageView img_bq;
	private List<String> title=Arrays.asList("关心","投票");
	@Override
	public void setRootView() {
		super.setRootView();
		setContentView(R.layout.activity_main04);
	}
	@Override
	public void initWidget() {
		super.initWidget();
		  initImageLoader();
		  	List<Fragment> listf = new ArrayList<Fragment>();
	    	Fragment fragment01= new CareAboutFragment();
			listf.add(fragment01);
			Fragment fragment02= new CardFragment();
			listf.add(fragment02);
			FragmentAdapter adapter=new FragmentAdapter(this.getSupportFragmentManager(), listf);
			mViewPage.setAdapter(adapter);
			mViewPage.setNoScroll(true);
			mViewPage.setOffscreenPageLimit(1); //mViewPage缓存页面数量
			indicator.setNum(listf.size());
			indicator.setTabItemTitle(title,0,2);
			indicator.setViewPageItem(mViewPage);
	}
    @SuppressWarnings("deprecation")
    private void initImageLoader() {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                this)
                .memoryCacheExtraOptions(480, 800)
                        // default = device screen dimensions
                .threadPoolSize(3)
                        // default
                .threadPriority(Thread.NORM_PRIORITY - 1)
                        // default
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                        // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13) // default
                .discCacheSize(50 * 1024 * 1024) // 缓冲大小
                .discCacheFileCount(100) // 缓冲文件数目
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(this)) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs().build();

        // 2.单例ImageLoader类的初始�??
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.init(config);
    }
    public static void setTab(int type){
		if(type==1){//关心
			mViewPage.setCurrentItem(0);
		}else{//投票
			mViewPage.setCurrentItem(1);
		}
		
	}
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}
}
